package dk.henrikkleist.knrradio;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class KNRRadio extends Activity implements OnClickListener{

	private Button buttonPlay;

	private Button buttonStopPlay;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		buttonPlay = (Button) findViewById(R.id.buttonPlay);
		buttonPlay.setOnClickListener(this);

		buttonStopPlay = (Button) findViewById(R.id.buttonStopPlay);
		buttonStopPlay.setOnClickListener(this);
		buttonStopPlay.setEnabled(false);
		
		playService();
	}
	
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.buttonPlay:
			playService();
			break;

		case R.id.buttonStopPlay:
			stopPlayService();
			break;
		}
	}

	private void stopPlayService() {
		stopService(new Intent(this, RadioService.class));
		buttonPlay.setEnabled(true);
		buttonStopPlay.setEnabled(false);
	}

	private void playService() {
		startService(new Intent(this, RadioService.class));
		buttonPlay.setEnabled(false);
		buttonStopPlay.setEnabled(true);
	}
}
